package com.logos.service.impl;

import com.logos.dao.BookDao;
import com.logos.service.BookService;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;


//@Component(value = "bookService")
@Service(value = "bookService")
public class BookServiceImpl implements BookService, InitializingBean, DisposableBean {

    // 解耦,删除new的方式创建的dao对象
    @Autowired
    // @Qualifier注解开启指定名称装配bean
    @Qualifier(value = "bookDao")
    private BookDao bookDao;
//    private UserDao userDao;

//    public BookServiceImpl(BookDao bookDao, UserDao userDao) {
//        this.bookDao = bookDao;
//        this.userDao = userDao;
//        System.out.println("service construct run...");
//    }

    // 提供set方法
//    public void setBookDao(BookDao bookDao) {
//        this.bookDao = bookDao;
//    }

//    public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }

    @Override
    public void save() {
        System.out.println("BookServiceImpl save...");
        bookDao.save();
//        userDao.save();
    }

    @Override
    public void destroy() throws Exception {
//        System.out.println("service destroy...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
//        System.out.println("service init...");
    }
}
